package com.cat.enumerate;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/coordinate-with-maximum-network-quality/description/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/21 16:38
 * @since JDK17
 */

public class Solution09 {
    int get(int[] tower, int[] pos, int radius) {
        int x1 = tower[0], y1 = tower[1], x2 = pos[0], y2 = pos[1];
        int d = ((int) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
        if (radius >= d) {
            return tower[2] / (1 + d);
        }
        return 0;
    }

    public int[] bestCoordinate(int[][] towers, int radius) {
        int[] ans = new int[2];
        int n = towers.length, max = 0, cur;
        for (int i = 0; i <= 50; i++) {
            for (int j = 0; j <= 50; j++) {
                // 枚举所有的点
                cur = 0;
                for (int k = 0; k < n; k++) {
                    cur += get(towers[k], new int[]{i, j}, radius);
                }
                if (cur > max) {
                    ans = new int[]{i, j};
                }
            }
        }

        return ans;
    }
}
